package com.ivt.utils;

import com.ivt.model.Attendance;
import com.ivt.model.Classes;
import com.ivt.model.Courses;
import com.ivt.model.Student;
import com.ivt.model.Teacher;
import com.ivt.model.view.AttendanceView;
import com.ivt.model.view.ClassesView;
import com.ivt.model.view.CoursesView;
import com.ivt.model.view.StudentView;
import com.ivt.model.view.TeacherView;
import com.ivt.utils.enums.Sign;

public class Convert {

	public static StudentView toStudentView(Student s) {

		StudentView view = new StudentView();

		if (null == s) {
			return null;
		}
		view.setAccount(s.getAccount());
		view.setAddress(s.getAddress());
		view.setAge(s.getAge());
		view.setBorn(s.getBorn());
		view.setName(s.getName());
		view.setSex(s.getSex());
		view.setStatus(s.getStatus());
		view.setStudentId(s.getId());
		view.setTel(s.getTel());
		if (null != s.getClasses()) {
			view.setClassesId(s.getClasses().getClassesId());
			view.setClassesName(s.getClasses().getName());
		}
		return view;

	}

	public static AttendanceView toAttendanceView(Attendance a) {

		AttendanceView view = new AttendanceView();

		if (null == a) {
			return null;
		}
		view.setAddress(a.getAddress());
		view.setAttendanceId(a.getAttendanceId());
		view.setCoordinate(a.getCoordinate());
		view.setSignTime(a.getSignTime());

		if (null != a.getStudent()) {
			view.setStudentId(a.getStudent().getId());
			view.setStudentName(a.getStudent().getName());
			if (null != a.getStudent().getClasses()) {
				view.setClassesId(a.getStudent().getClasses().getClassesId());
				view.setClassesName(a.getStudent().getClasses().getName());
			}
		}

		if (null != a.getCourses()) {
			view.setCoursesName(a.getCourses().getName());
		}
		if (Sign.IN == a.getSign()) {
			view.setSign("签到");
		}
		if (Sign.OUT == a.getSign()) {
			view.setSign("签退");
		}
		view.setCoursesTime(a.getCoursesTime());
		return view;

	}

	public static TeacherView toTeacherView(Teacher in) {

		TeacherView out = new TeacherView();

		if (null == in) {
			return null;
		}
		out.setAccount(in.getAccount());
		out.setAddress(in.getAddress());
		out.setAge(in.getAge());
		out.setBorn(in.getBorn());
		out.setName(in.getName());
		out.setSex(in.getSex());
		out.setStatus(in.getStatus());
		out.setId(in.getId());
		out.setTel(in.getTel());
		if (null != in.getClasses()) {
			out.setClassesId(in.getClasses().getClassesId());
			out.setClassesName(in.getClasses().getName());
		}
		return out;

	}

	public static CoursesView toCoursesView(Courses in) {
		if (null == in) {

			return null;
		}
		CoursesView out = new CoursesView();

		out.setBeginTime(in.getBeginTime());
		out.setId(in.getId());
		out.setDescription(in.getDescription());
		out.setName(in.getName());
		out.setStatus(in.getStatus());

		if (null != in.getTeacher()) {
			out.setTeacherId(in.getTeacher().getId());
			out.setTeacherName(in.getTeacher().getName());
		}
		return out;
	}

	public static ClassesView toClassesView(Classes c) {
		ClassesView view = null;

		if (null == c) {
			return view;
		}
		view = new ClassesView();
		view.setClassesId(c.getClassesId());
		view.setDescription(c.getDescription());
		view.setName(c.getName());
		view.setStatus(c.getStatus());

		return view;
	}
}
